package cn.chenfeifx.core.controls;

import cn.chenfeifx.core.common.ResourcesLoader;
import javafx.beans.property.StringProperty;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined;
import org.kordamp.ikonli.javafx.FontIcon;

/**
 * 简单头部
 */
class Header extends StackPane {

    private final Label titleLabel;

    public Header(String title, EventHandler<MouseEvent> closeEventEventHandler) {
        titleLabel = new Label(title);
        StackPane.setAlignment(titleLabel, Pos.CENTER_LEFT);
        FontIcon closeIcon = FontIcon.of(AntDesignIconsOutlined.CLOSE);
        StackPane.setAlignment(closeIcon, Pos.CENTER_RIGHT);
        getChildren().addAll(titleLabel, closeIcon);
        getStyleClass().add("header");
        titleLabel.getStyleClass().add("title");
        closeIcon.getStyleClass().add("close");
        closeIcon.setOnMouseClicked(closeEventEventHandler);
    }

    public StringProperty titleProperty() {
        return this.titleLabel.textProperty();
    }

    @Override
    public String getUserAgentStylesheet() {
        return ResourcesLoader.load("/cn/chenfeifx/core/css/header.css");
    }
}
